package com.atguigu.spzx.manager.service.impl;

import com.atguigu.spzx.common.log.annotation.Log;
import com.atguigu.spzx.manager.mapper.BrandMapper;
import com.atguigu.spzx.manager.service.BrandService;
import com.atguigu.spzx.model.entity.product.Brand;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class BrandServiceImpl implements BrandService {

    @Autowired
    private BrandMapper brandMapper;

    @Log(title = "商标查询",businessType = 1)
    @Override
    public PageInfo<Brand> getBrandPageList(Integer page, Integer limit) {
        //开启分页查询
        PageHelper.startPage(page,limit);
        //查询数据
        List<Brand> brandList= brandMapper.getBrandPageList();
        PageInfo<Brand> pageInfo=new PageInfo<>(brandList);
        return pageInfo;
    }

    @Override
    public void updateById(Brand brand) {
        brandMapper.updateById(brand);
    }

    @Transactional
    @Log(title = "商标保存",businessType = 1)
    @Override
    public void save(Brand brand) {
        System.out.println("执行保存商标前");
        brandMapper.insertBrand(brand);
        System.out.println("执行保存商标后");
    }

    @Override
    public void deleteById(Long id) {
        brandMapper.deleteById(id);
    }

    @Override
    public List<Brand> findAll() {
        List<Brand> brandList= brandMapper.findAll();
        return brandList;
    }
}
